package com.management.controller;

import com.management.po.Authority;
import com.management.po.SecPostAnd;
import com.management.po.Section;
import com.management.po.SectionAndPost;
import com.management.service.*;
import com.management.vo.SecPostAndVO;
import com.management.vo.SectionAndPostVO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
import javax.annotation.Resource;

/**
 * @author ls
 * @category
 * 科室职位权限控制器
 */
@Controller
public class SectionAndPostController {
    Logger logger =Logger.getLogger(SectionAndPostController.class);
    @Resource
    AuthorityService authorityService;
    @Resource
    SecPostAndService secPostAndService;
    @RequestMapping("sectionandpost")
    public String sectionandpost(int sectionAndPostId, Model model){
        List<SecPostAndVO> list = secPostAndService.findBySectionAndPostId(sectionAndPostId);
        model.addAttribute("list",list);
        model.addAttribute("sectionAndPostId",sectionAndPostId);
        return "postandauthortiy";
    }
   @RequestMapping("/deleteauthority")
    public String delete(int secPostAndId,int sectionAndPostId ){
      boolean flag =  secPostAndService.delete(secPostAndId);
         logger.info(flag?"删除成功":"删除失败");
         return "redirect:sectionandpost.action?sectionAndPostId="+sectionAndPostId;
   }
   @RequestMapping("/toaddauthority")
    public String toadd(Model model,int sectionAndPostId){
        logger.info("进入toaddauthority控制器");
       List<Authority> list = authorityService.findByType(2);
       logger.info(list);
       model.addAttribute("list",list);
       model.addAttribute("sectionAndPostId",sectionAndPostId);
        return "privileges";
   }
   @RequestMapping("/addauthority")
    public String add(SecPostAnd secPostAnd,int sectionAndPostId){
       logger.info("进入addauthority控制器");
       boolean flag =secPostAndService.add(secPostAnd);
       logger.info(flag);
       return "redirect:sectionandpost.action?sectionAndPostId="+sectionAndPostId;
   }
}
